//
//  ReloadView.m
//  News
//
//  Created by wallstreetcn on 14-5-5.
//  Copyright (c) 2014年 wallstreetcn. All rights reserved.
//

#import "ReloadView.h"

@implementation ReloadView

#pragma mark - life cycle
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = frame;
        self.backgroundColor = [UIColor clearColor];
        //[self addThemeChanged];
    }
    return self;
}

#pragma mark - setter
- (void)setViewState:(ViewState)viewState
{
    switch (viewState)
    {
        case ViewStateLoad:
            _control.enabled = NO;
            //_bgImageV.image = kIMG(@"load");
            break;
            
        case ViewStateReLoad:
            _control.enabled = YES;
            //_bgImageV.image = kIMG(@"reload");
            break;
            
        default:
            break;
    }
//    [self performSelector:@selector(stopAnimate) withObject:nil afterDelay:0.1];
}

#pragma mark - public methods
//初始化
- (id)initWithFrame:(CGRect)frame RootViewController:(id)vc
{
    if (self == [self initWithFrame:frame]) {
        self.rootVC = vc;
        [self buildUI];
    }
    return self;
}

//开启动画
- (void)startAnimate
{
    self.hidden = NO;
//    [self performSelector:@selector(threadStartAnimating:) withObject:nil afterDelay:0.01];
//    [NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];
    [_indicator startAnimating];
}

- (void) threadStartAnimating:(id)data
{
    [_indicator startAnimating];
}

//停止动画
- (void)stopAnimate
{
//    [_indicator stopAnimating];
    [self performSelector:@selector(stop) withObject:nil afterDelay:0.1];
}

- (void)stop
{
    [_indicator stopAnimating];
}

//UI界面初始化
- (void)buildUI
{
    /*
    UIControl *control = [[UIControl alloc]initWithFrame:self.bounds];
    [control addTarget:self action:@selector(selfTapped:) forControlEvents:UIControlEventTouchUpInside];
    _control = control;
    [self addSubview:control];
    
    float width = 150;
    float height = 100;
    //UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake((kVIEW_W(self)-width)/2, (kVIEW_H(self)-height)*0.4, width, height)];
    //_bgImageV = iv;
    [self addSubview:iv];
     */
    
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    indicator.hidesWhenStopped = YES;
    indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    _indicator = indicator;
    [self addSubview:indicator];
    //[self setViewState:ViewStateLoad];
    //[self changeMode];
}





@end
